<?php
// 判断用户是否是管理员
session_start();
if($_SESSION['userinfo']["isadmin"]!=1) die("<a href='#' onclick='window.history.back()'>权限不足</a>");

/*
 * 连接数据库查询
 */
$db = mysqli_connect("localhost","root","123456","bbs");
$sql = "select * from type ";
$userTypes = array();
$pre = $db->prepare($sql);
$pre->bind_result($tid,$type_code,$type_name);
$pre->execute();
while($pre->fetch()){
    $userType = array();
    $userType['tid'] = $tid;
    $userType['type_code'] = $type_code;
    $userType['type_name'] = $type_name;
    //单个添加到数组中
    $userTypes[] = $userType;
}

?>
<span>
    <?php
    echo $_SESSION["msg"];
    $_SESSION["msg"]=null;
    ?>
</span>
<div>
    <a href="addType.php">新增</a>
</div>

<table>
    <tr>
        <th>编号</th>
        <th>类型代码</th>
        <th>类型名称</th>
        <th>操作</th>
    </tr>
    <?php foreach ($userTypes as $userType):  ?>
        <tr>
            <td><?php echo $userType['tid'] ?></td>
            <td><?php echo $userType['type_code'] ?></td>
            <td><?php echo $userType['type_name'] ?></td>
            <td>
                <a href="updateType.php?tid=<?php echo $userType['tid'] ?>">修改</a> &emsp;
                <a href="delType.php?tid=<?php echo $userType['tid'] ?>">删除</a>
            </td>
        </tr>

    <?php endforeach;  ?>
</table>
